<?php
namespace app\admin\logic;
use think\facade\Filesystem;
use think\facade\Request;
use think\facade\View;

class Goods
{
    //展示页逻辑
    public static function goodsWhere()
    {
        $get=Request::get();
        View::assign($get);
        //时间排序
        $order=Request::get('order','');
        if ($order==''){
            View::assign('order','addtime desc');
            View::assign('pai','↓');
        }elseif ($order=='addtime desc'){
            View::assign('order','addtime');
            View::assign('pai','↑');
        }elseif ($order=='addtime'){
            View::assign('order','id');
            View::assign('pai','id');
        }elseif ($order=='id'){
            View::assign('order','');
            View::assign('pai','');
        }

        $wheres='';//点击时间排序留值
        $where=[];//where条件
        if (isset($get['is_show'] )&& $get['is_show']!=''){
            $where['is_show']=$get['is_show'];
            $wheres.='&is_show='.$get['is_show'];
        }
        if (isset($get['is_hot']) && $get['is_hot']!=''){
            $where['is_hot']=$get['is_hot'];
            $wheres.='&is_hot='.$get['is_hot'];
        }
        if (isset($get['is_down']) && $get['is_down']!=''){
            $where['is_down']=$get['is_down'];
            $wheres.='&is_down='.$get['is_down'];
        }
        if (isset($get['cid']) && !empty($get['cid'])){
            $where['cid']=$get['cid'];
            $wheres.='&cid='.$get['cid'];
        }
        if (isset($get['keywords']) && !empty($get['keywords'])){
            $where['name']=$get['keywords'];
            $wheres.='&keywords='.$get['keywords'];
        }
        View::assign('wheres',$wheres);

        return [$where,$order];
    }
    //添加页的逻辑
    public static function xiuGoodWhere()
    {
        //图片没接
        if (Request::isPost()){
            $list=Request::post();

            $file=Request::file();

            $arr=[];

            if ($file){
                validate(['img'=>'filesize:9999910240|fileExt:jpg,png'])->check($file);
                $savename=Filesystem::putFile('images',$file['img'],'sha1');
                $savename=str_replace('/','\\',$savename);
                if (isset($file))         $arr['photo_x']=$savename;
            }
            if (isset($list['id']))         $arr['id']=$list['id'];
            //修改的图片
            if (isset($list['pro_number'])) $arr['pro_number']=$list['pro_number'];
            if (isset($list['name']))       $arr['name']=$list['name'];
            if (isset($list['price']))      $arr['price']=$list['price'];
            if (isset($list['price_shop'])) $arr['price_shop']=$list['price_shop'];
            if (isset($list['num']))        $arr['num']=$list['num'];
            if (isset($list['cid']))        $arr['cid']=$list['cid'];
            if (isset($list['content']))    $arr['content']=$list['content'];
            if (isset($list['sort']))       $arr['sort']=$list['sort'];
            if (isset($list['renqi']))      $arr['renqi']=$list['renqi'];
            if (isset($list['company']))    $arr['company']=$list['company'];
            if (isset($list['is_show']))    $arr['is_show']=isset($list['is_show'])?'1':'0';
            if (isset($list['is_hot']))     $arr['is_hot']=isset($list['is_hot'])?'1':'0';
            if (isset($list['is_down']))    $arr['is_down']=isset($list['is_down'])?'1':'0';
            return $arr;
        }
    }
    //添加页的逻辑
    public static function goodAddWhere()
    {
        if (Request::isPost()){
            $list=Request::post();

            $file=Request::file();

            $arr=[];

            if ($file){
                validate(['img'=>'filesize:9999910240|fileExt:jpg,png'])->check($file);
                $savename=Filesystem::putFile('images',$file['img'],'sha1');
                $savename=str_replace('/','\\',$savename);
                if (isset($file))         $arr['photo_x']=$savename;
            }
            if (isset($list['id']))         $arr['id']=$list['id'];
            //修改的图片
            if (isset($list['pro_number'])) $arr['pro_number']=$list['pro_number'];
            if (isset($list['name']))       $arr['name']=$list['name'];
            if (isset($list['price']))      $arr['price']=$list['price'];
            if (isset($list['price_shop'])) $arr['price_shop']=$list['price_shop'];
            if (isset($list['num']))        $arr['num']=$list['num'];
            if (isset($list['cid']))        $arr['cid']=$list['cid'];
            if (isset($list['content']))    $arr['content']=$list['content'];
            if (isset($list['sort']))       $arr['sort']=$list['sort'];
            if (isset($list['renqi']))      $arr['renqi']=$list['renqi'];
            if (isset($list['company']))    $arr['company']=$list['company'];
            if (isset($list['is_show']))    $arr['is_show']=isset($list['is_show'])?'1':'0';
            if (isset($list['is_hot']))     $arr['is_hot']=isset($list['is_hot'])?'1':'0';
            if (isset($list['is_down']))    $arr['is_down']=isset($list['is_down'])?'1':'0';
            return $arr;
        }
    }
    //软删除
    public static function goodsDel()
    {
        if (Request::isGet()){
            if (Request::get('delId')!=''){
                return Request::get('delId');
            }
        }
    }
    //删除页的真删逻辑
    public static function shanGoodDelWhere()
    {
        if (Request::isGet()){
            if (Request::get('shanId')!=''){
                return Request::get('shanId');
            }
        }
    }
    //删除页的恢复逻辑
    public static function huiGoodDelWhere()
    {
        if (Request::isGet()){
            if (Request::get('huiId')!=''){
                return Request::get('huiId');
            }
        }
    }
}